/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.mochaccino.framework.transaction.jsr250;

import com.google.common.base.Preconditions;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;

public final class BitronixTransactionManagerWrapper implements TransactionManager {

	private bitronix.tm.BitronixTransactionManager delegate;

	@Inject
	public BitronixTransactionManagerWrapper( bitronix.tm.BitronixTransactionManager delegate ) {
		this.delegate = Preconditions.checkNotNull( delegate );
	}

	@Override
	public void begin() throws NotSupportedException, SystemException {
		delegate.begin();
	}

	@Override
	public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
		delegate.commit();
	}

	@Override
	public int getStatus() throws SystemException {
		return delegate.getStatus();
	}

	@Override
	public Transaction getTransaction() throws SystemException {
		return delegate.getTransaction();
	}

	@Override
	public void resume( Transaction transaction ) throws InvalidTransactionException, IllegalStateException, SystemException {
		delegate.resume( transaction );
	}

	@Override
	public void rollback() throws IllegalStateException, SecurityException, SystemException {
		delegate.rollback();
	}

	@Override
	public void setRollbackOnly() throws IllegalStateException, SystemException {
		delegate.setRollbackOnly();
	}

	@Override
	public void setTransactionTimeout( int seconds ) throws SystemException {
		delegate.setTransactionTimeout( seconds );
	}

	@PreDestroy
	public void shutdown() {
		delegate.shutdown();
	}

	@Override
	public Transaction suspend() throws SystemException {
		return delegate.suspend();
	}
}
